/**
 * 
 */
package com.cbank.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cbank.dao.UserDao;
import com.cbank.domain.User;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:cBank
 * </p>
 * <p>
 * Contact: 1027448479@qq.com
 * </p>
 * 
 * @author Ag
 * @date 2016年12月13日
 */
@Service
public class UserService {
	@Autowired
	private UserDao userDao;

	public void save(User obj) {
		User u = userDao.getByViewId(obj.getViewId());
		if (u == null) {
			this.userDao.insert(obj);
		} else {
			this.userDao.update(obj);
		}
	}

	public User getByViewId(Long viewId) {
		User u = userDao.getByViewId(viewId);
		return u;
	}

	public User getByViewIdAndToken(long viewId, String token) {
		User u = userDao.getByViewIdAndToken(viewId, token);
		return u;
	}

	public User getById(Long id) {
		User u = userDao.getById(id);
		return u;
	}
	
	public User getByNamePwd(String name,String pwd) {
		User u = userDao.getByNamePwd(name,pwd);
		return u;
	}

	public List<User> getList(Integer index, Integer pagerSize) {
		return this.userDao.getPage(index, pagerSize);
	}

	public Integer getCount() {
		return userDao.getCount();
	}

}
